Waiting for export to complete

I am trying to make a script that imports files, makes modifications, and exports them.

When scripting, is there way to know when an export is complete? I would like to start looking for the next file when lux.exportFile is complete.

I would like to put in a loop that waits for the export to complete before moving on.

Something like:
while lux.isRendering()
time.sleep(1)

isRendering isn’t part of the lux library. I looked for similar commands like lux.isInteractive() and that doen’t exist either.

I also tried flagging “pause” before importing and exporting and that’s not working as expected.

while lux.isPaused():
time.sleep(1)

The script works great for a small amount of files, however, it eventually runs out of memory.

Is there a way to clear cache more aggressively than lux.newScene(), such as lux.deleteScene()?

Thanks.

Hi @keyshot.advocate.4 - I messaged our support team and someone should get back to you. Thanks.

Hey Ryan,

I took a look at the script you provided to Arlene.
Please be aware that scripting functions that are not listed in our documentation, do not exist.
So “isRendering” ,“isExporting” or "is “Interactive()” will not work.
Please refer to: https://media.keyshot.com/scripting/doc/11.3/lux.html for the available functions.

Also not that the functions in KeyShot are designed such that they finish their action before continuing with the script.
So if you use functions like renderImage() or exportFile(), the operation will be finalized before the script continues.
Note: exeptions are operations in external applications, such as Sending a rendering to the network or background rendering.

Using a while loop with a sleep() should therefore not be needed, as the operation should be done by that time.

As for the memory issue:
I noticed that you use “with open(…)” on the glb file before exporting.
and never Close the File again.

This is handled in the ExportFile function, and is not needed. You can just call lux.ExportFile().

While i could no see signs for this causing the memory build up, it might cause loose handles.

Regarding running out of memory:

lux.newScene() should clear the cache completely, if it does not there might be an issue somewhere.
Sadly could not observe this when trying on my system.
It is possibly linked to one of the files your are importing.

How many files are we talking about and what CAD software do they originate in?
Ideally provide the files for us to investigate.

Thanks

Thanks for the reply.

I understand that those functions are not in the documentation and do not exist. I was just looking for some method of checking “is it done exporting”. Some type of event that lets me know that the initializing and rendering windows are closed. I understand Python runs one line at a time, and it should wait until the export is complete before moving on to the next line.

I’ve modified the code to get rid of the sleep function, as well as the unnecessary open.

Make GLB 5.0.py.txt (2.1 KB)

The files originate from Solid Edge, and I’m trying to convert about 400 files at a time. I’ll private message you a link to some of the files.

Here is a video of what the rendering looks like (sped up because it’s a very long video).

Still experiencing the same issues, the “initializing” window in Keyshot seems to open over and over again until Keyshot eventually freezes.

The “initializing” and “rendering” windows never go away, even after clearing the scene with the lux.newScene function. If you look in the resource monitor (in Windows), the number of threads keeps increasing. That’s not what I expect to happen. The windows keep building on top of each other until eventually Keyshot runs out of memory and the script cannot run anymore.

Thanks again

Hey,
Sorry for the late reply.
I can see the progress windows not closing correctly when keyshot is done opening the files" I willl create an issue for that.

But that seems to not be the main culprit. Some of the files you provided do not at all import in KeyShot and freeze KeyShot 11, also when using regular import.
Among these “42-00-40814114+G.asm”

The same File imports without problems in the latest beta of KeyShot 2023.1, could i get you to try to run the script in the Beta?

You can find it here: https://community.keyshot.com/forum/t/new-2023-beta-release-build-163/323
Let me know if you can not acces that thread.

Note: I did not see a memory build up, but the above issue seems to match your experience.

Best regards
Niko

Niko,

I do not see the memory build up in the beta version. However, I do see the freezing and “shadow” of the render window. Some of the files are complicated assembly files with many linked parts, and perhaps that’s why they are not opening natively in Keyshot.

Thanks,

Ryan